package com.ticket.api.controller;

import com.ticket.api.service.TbMarketParkInfoService;
import com.ticket.api.service.TbUserInfoService;
import com.ticket.common.string.StringUtil;
import com.ticket.common.time.CommonFunction;
import com.ticket.db.entity.TblMarketParkInfo;
import com.ticket.db.entity.TblUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/park")
public class TbMarketParkInfoController {

    @Autowired
    TbMarketParkInfoService tbMarketParkInfoService;

    @Autowired
    TbUserInfoService userInfoService;

    @RequestMapping("parkInfoAll")
    public List<TblMarketParkInfo> findTblMarketParkInfoAll(String userId) {
        List<TblMarketParkInfo> list = tbMarketParkInfoService.findTblMarketParkInfoAll(userId);
        for (int item=0;item<list.size();item++) {
            list.get(item).setLastUpdateTime(CommonFunction.Toyymmdd(list.get(item).getLastUpdateTime()));
        }
        return list;
    }

    @RequestMapping("parkInfoByCondition")
    public List<TblMarketParkInfo> findTblMarketParkInfoByCondition(TblMarketParkInfo info) {
        System.out.println(info.toString());
            try{
                List<TblMarketParkInfo>  list=  tbMarketParkInfoService.findTblMarketParkInfoByCondition(info);
                for (int item=0;item<list.size();item++) {
                    list.get(item).setLastUpdateTime(CommonFunction.Toyymmdd(list.get(item).getLastUpdateTime()));
                    TblUserInfo userInfoById = userInfoService.findTblUserInfoById(list.get(item).getCreateUser());
                    list.get(item).setAvatar(userInfoById.getRemarks());
                    list.get(item).setUserName(userInfoById.getUserName());
                }
                return list;
            }catch (Exception e){
                e.printStackTrace();
                return null;
            }

    }

    @RequestMapping("parkInfoInsert")
    public Integer insertTblMarketParkInfo(TblMarketParkInfo info) {
        return tbMarketParkInfoService.insertTblMarketParkInfo(info);
    }

    @RequestMapping("parkInfoUpdate")
    public Integer updateTblMarketParkInfo(TblMarketParkInfo info) {
        return tbMarketParkInfoService.updateTblMarketParkInfo(info);
    }
}
